package com.example.feitou.listview;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class MyAdapter extends BaseAdapter{
    private ArrayList<Fruit> fruits;
    private Context context;

    public MyAdapter(Context context,ArrayList<Fruit> fruits){
        this.context = context;
        this.fruits = fruits;
    }
    @Override
    public int getCount() {
        return fruits.size();
    }

    @Override
    public Object getItem(int i) {
        return fruits.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        view = layoutInflater.inflate(R.layout.my_list_item,viewGroup,false);

/*        ImageView headView = view.findViewById(R.id.headView);
        headView.setImageResource(fruits.get(i).getImgId());*/

        TextView nameView = view.findViewById(R.id.nameView);
        nameView.setText(fruits.get(i).getName());

        TextView sizeView = view.findViewById(R.id.sizeView);
        sizeView.setText(String.valueOf(fruits.get(i).getSize()));

        return view;
    }
}
